package com.dys.testthis;

/**
 * @className: com.dys.testthis.Person
 * @description: this的使用
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/07/15 下午7:16
 */
public class Person {
    String name;
    int age;
    double height;

    public Person() {
    }

    public Person(int age) {
        this.age = age;
    }

    public Person(int age, double height) {
        this(age);
        this.height = height;
    }

    public Person(int age, double height, String name) {
        // this可以修饰构造器
        this(age, height);
        // this.age = age;
        // this.height = height;
        this.name = name;
    }

    public Person(String a, int b, double c) {
        // 当属性名与形参名没有重复时,this.可以省略不写
        name = a;
        age = b;
        height = c;
    }

    public void eat() {
        int age = 10;
        System.out.println(age);// 就近原则
        System.out.println(this.age);
        System.out.println("吃的方法");
    }

    public void study() {
        System.out.println("学习");
    }

    public void play() {
        // System.out.println("学习");
        // this.study(); // this.可以省略不写
        this.study();
        System.out.println("上网");
    }

    /**
     * 这是一个main()方法,是应用程序的入口
     *
     * @param args 方法的形参列表,是一个字符串数组,包含了从命令行传递给程序的参数
     */
    public static void main(String[] args) {
        Person xl = new Person("萧炎", 20, 175.5);
        Person xl2 = new Person(20, 175.5, "唐三");
        xl.eat();
        xl2.play();
    }
}
